package com.example.controller;

import com.example.pojo.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileUploadContorller {

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws IOException {
        //把文件的内容存储到本地磁盘上
        String filename = file.getOriginalFilename();
        //保证文件名字唯一，防止文件覆盖 借助uuid
        String fileName = UUID.randomUUID().toString()+"."+filename.substring(filename.lastIndexOf("."));
        file.transferTo(new File("C:\\Users\\wsp09\\Desktop\\java11\\uploadFiel\\"+fileName));
        return Result.success("url访问地址");
    }
}
